﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CH.Easy.Utility;
using System.Text.RegularExpressions;
using System.Web;
using CH.Easy.UI.Domain;

namespace CH.Easy.UI.Domain.PageAgg
{
    public class PageLayout 
    {
        string positionPattern = @"{position.*?\/}";
        StringBuilder template { get; set; }
        public PageLayout(string path, BasePage page)
        {
            if (string.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("路径不可为空");
            }
            //读取模板 
            this.template = new StringBuilder(FileHelper.GetFileByString(path));
            //分析模板上面的位置信息
            Regex r = new Regex(positionPattern, RegexOptions.IgnoreCase);
            MatchCollection mc = r.Matches(template.ToString());
            foreach (Match item in mc)
            {
                //循环加载当前位置上面的模块信息
                LayoutPosition pos = new LayoutPosition(item.Value, page);
                this.template.Replace(item.Value, pos.Template.ToString());
            }
        }

        public StringBuilder GetTemplate() 
        {
            return this.template;
        }


    }
}
